package cn.misora.mymockito;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.implementation.FixedValue;
import net.bytebuddy.matcher.ElementMatchers;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    void testByteBuddy() {


        DynamicType.Unloaded type = new ByteBuddy()
                .subclass(Math.class)
                .method(ElementMatchers.isToString())
                .intercept(FixedValue.value("hello world"))
                .make();


        Class<?> dynamicType = type.load(getClassLoader()).getLoaded();

        try {
            String result = dynamicType.newInstance().toString();
            Log.i("tag", result);
        } catch (Exception e) {
            Log.i("tag", e.toString());
        }


    }
}